package com.huawei.appmarket.service.store.awk.card;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.Space;
import com.huawei.appmarket.service.store.awk.bean.HorizonalHomeCardItemBean;
import com.huawei.appmarket.service.store.awk.bean.SixAppIconCardBean;
import java.util.ArrayList;
import java.util.List;
import o.cgz;
import o.chc;
import o.chy;
import o.dyf;
import o.epv;
import o.CollectCheck;
import o.ewm.d;
import o.ewm.j;

public class SixAppIconCard extends BaseDistCard {
    private LinearLayout ʻ;
    private LinearLayout ʼ;
    private HorizontalScrollView ʽ;
    private TextView ˋ;
    private int ˋॱ;
    private List<cgz> ˏॱ = new ArrayList();
    private dyf ͺ = new dyf();
    private LinearLayout ॱॱ;
    private chy ᐝ;

    public SixAppIconCard(Context context) {
        super(context);
    }

    public cgz ˏ(View view) {
        this.ˋ = (TextView) view.findViewById(j.ʼﾞ);
        this.ॱॱ = (LinearLayout) view.findViewById(j.ʼꞌ);
        this.ʻ = (LinearLayout) view.findViewById(j.ꞌˊ);
        this.ʼ = (LinearLayout) view.findViewById(j.ʼᵔ);
        this.ʽ = (HorizontalScrollView) view.findViewById(j.ʽˑ);
        ʽ(view);
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        SixAppIconCardBean sixAppIconCardBean = (SixAppIconCardBean) cardBean;
        List ˊ = sixAppIconCardBean.ˊ();
        this.ˋ.setText(sixAppIconCardBean.v_());
        this.ˋॱ = chc.ˊˊ();
        LayoutParams layoutParams = new LayoutParams(0, -1);
        layoutParams.weight = 1.0f;
        if (!CollectCheck.isEmpty(ˊ)) {
            if (epv.ʼ(this.ʼॱ)) {
                ˊ(ˊ, layoutParams);
                if (ˊ.size() <= 6) {
                    this.ॱॱ.setVisibility(8);
                } else {
                    this.ॱॱ.setVisibility(0);
                }
            } else {
                ॱ(ˊ, this.ˋॱ, layoutParams);
                if (ˊ.size() <= this.ˋॱ) {
                    this.ॱॱ.setVisibility(8);
                } else {
                    this.ॱॱ.setVisibility(0);
                }
            }
        }
        this.ˊˋ.post(new Runnable(this) {
            final /* synthetic */ SixAppIconCard ˎ;

            {
                this.ˎ = r1;
            }

            public void run() {
                if (this.ˎ.ˋॱ * this.ˎ.ʼॱ.getResources().getDimensionPixelOffset(d.ʻˋ) > this.ˎ.ˊˋ.getWidth()) {
                    ((ViewGroup) this.ˎ.ˊˋ).removeView(this.ˎ.ʻ);
                    this.ˎ.ʽ.removeAllViews();
                    this.ˎ.ʽ.addView(this.ˎ.ʻ);
                }
            }
        });
    }

    private void ˊ(List<HorizonalHomeCardItemBean> list, LayoutParams layoutParams) {
        int i;
        if (list.size() <= 3) {
            this.ʼ.setVisibility(8);
        } else {
            this.ʼ.setVisibility(0);
        }
        this.ʻ.removeAllViews();
        this.ʼ.removeAllViews();
        for (i = 0; i < this.ˋॱ; i++) {
            HorizonalHomeCardItemBean horizonalHomeCardItemBean;
            if (i >= list.size()) {
                horizonalHomeCardItemBean = (HorizonalHomeCardItemBean) list.get(0);
            } else {
                horizonalHomeCardItemBean = (HorizonalHomeCardItemBean) list.get(i);
            }
            View ˎ = ˎ(horizonalHomeCardItemBean);
            if (i >= list.size()) {
                ˎ.setVisibility(4);
            }
            if (i > 0) {
                this.ʻ.addView(new Space(this.ʼॱ), layoutParams);
            }
            this.ʻ.addView(ˎ);
        }
        for (i = 0; i < this.ˋॱ; i++) {
            if (i + 3 >= list.size()) {
                horizonalHomeCardItemBean = (HorizonalHomeCardItemBean) list.get(0);
            } else {
                horizonalHomeCardItemBean = (HorizonalHomeCardItemBean) list.get(i + 3);
            }
            ˎ = ˎ(horizonalHomeCardItemBean);
            if (i + 3 >= list.size()) {
                ˎ.setVisibility(4);
            }
            if (i > 0) {
                this.ʼ.addView(new Space(this.ʼॱ), layoutParams);
            }
            this.ʼ.addView(ˎ);
        }
    }

    private void ॱ(List<HorizonalHomeCardItemBean> list, int i, LayoutParams layoutParams) {
        this.ʼ.setVisibility(8);
        this.ʻ.removeAllViews();
        this.ʼ.removeAllViews();
        for (int i2 = 0; i2 < i; i2++) {
            HorizonalHomeCardItemBean horizonalHomeCardItemBean;
            if (i2 >= list.size()) {
                horizonalHomeCardItemBean = (HorizonalHomeCardItemBean) list.get(0);
            } else {
                horizonalHomeCardItemBean = (HorizonalHomeCardItemBean) list.get(i2);
            }
            View ˎ = ˎ(horizonalHomeCardItemBean);
            if (i2 >= list.size()) {
                ˎ.setVisibility(4);
            }
            if (i2 > 0) {
                this.ʻ.addView(new Space(this.ʼॱ), layoutParams);
            }
            this.ʻ.addView(ˎ);
        }
    }

    private View ˎ(HorizonalHomeCardItemBean horizonalHomeCardItemBean) {
        cgz sixAppIconItemCard = new SixAppIconItemCard(this.ʼॱ);
        View inflate = LayoutInflater.from(this.ʼॱ).inflate(sixAppIconItemCard.ˋ(), null);
        sixAppIconItemCard.ˏ(inflate);
        sixAppIconItemCard.ˉ().setClickable(true);
        sixAppIconItemCard.ˏ((CardBean) horizonalHomeCardItemBean);
        sixAppIconItemCard.ॱ(ˎ());
        ॱ(sixAppIconItemCard);
        return inflate;
    }

    private chy ˎ() {
        return this.ᐝ;
    }

    public void ॱ(final chy o_chy) {
        this.ᐝ = o_chy;
        this.ॱॱ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ SixAppIconCard ˋ;

            public void onClick(View view) {
                if (o_chy != null) {
                    o_chy.ˏ(9, this.ˋ);
                }
            }
        });
    }

    public void ॱ(cgz o_cgz) {
        if (o_cgz != null && this.ˏॱ != null) {
            this.ˏॱ.add(o_cgz);
        }
    }

    public ArrayList<String> ˋ() {
        ArrayList<String> arrayList = new ArrayList();
        for (cgz o_cgz : this.ˏॱ) {
            View ˉ = o_cgz.ˉ();
            if (ˉ.getVisibility() == 0 && this.ͺ.ˎ(ˉ)) {
                CardBean ˌ = o_cgz.ˌ();
                if (ˌ instanceof BaseCardBean) {
                    arrayList.add(ˌ.ॱॱ() + "#$#" + ((BaseCardBean) ˌ).u_());
                }
            }
        }
        return arrayList;
    }
}
